<template>
	<div class="evidence-unit-eviChangeLoc-container">
		<el-drawer v-model="drawer" title="选择位置 " direction="rtl" size="80%" :before-close="closeDialog" :destroy-on-close="true">
			<store-index :isShow="1" :isInOut="1" :height="0" />
		</el-drawer>
	</div>
</template>

<script lang="ts">
import { reactive, toRefs, getCurrentInstance, watch, ref, onUnmounted } from 'vue';
import storeIndex from '/@/views/system/store/index.vue';
import { putEvidenceLocation } from '/@/api/evidence/index';
import { ElMessage } from 'element-plus';
export default {
	name: 'eviChangeLoc',
	components: { storeIndex },
	props: { selectionEvidences: Array },
	setup(props, { emit }) {
		const { proxy } = getCurrentInstance() as any;
		const state = reactive({});
		const drawer = ref(false);
		// 关闭弹窗
		const closeDialog = () => {
			drawer.value = false;
		};
		proxy.mittBus.on('changeLocation', (data: any) => {
			putEvidenceLocation({
				LocationCode: data.code,
				LocationId: data.id,
				LocationName: data.name,
				EvidenceIds: props.selectionEvidences.map((x) => {
					return x.id;
				}),
			}).then((res: any) => {
				if (res.success) {
					if (res.data) {
						try {
							Formium.external.callDevice.sysCabinetFunction(JSON.stringify(res.data));
						} catch {}
					}
					ElMessage({ message: '操作成功', type: 'success' });
					drawer.value = false;
					emit('reload');
				}
			});
		});
		onUnmounted(() => {
			proxy.mittBus.off('changeLocation');
		});
		return {
			closeDialog,
			drawer,
			...toRefs(state),
		};
	},
};
</script>
